﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace CalemShop
{
    class DBConnection
    {
        private static string connectString = "Server=localhost;Database=calemShop;Uid=root;Pwd=rroott;CharSet=utf8;Convert Zero Datetime=True";
        //private const string connectString = "Server=shopcalem.net;Database=calemShop;Uid=root;Pwd=rroott;CharSet=utf8;Convert Zero Datetime=True";


        private DBConnection()
        {

        }

        public static string ConnectionString
        {
            get { return connectString;}
            set { connectString = value; }
        }

        public static bool testConnection()
        {
            MySqlConnection connection = new MySqlConnection(connectString);
            try
            {
                connection.Open();
                bool result = connection.Ping();
                return result;
            }
            finally
            {
                connection.Close();
            }
        }

        public static MySqlConnection getConnection()
        {
            return new MySqlConnection(connectString);
        }

        public static MySqlConnection getGlobalConnection()
        {
            return new MySqlConnection(RuntimeData.GetGlobalSqlConnectionString());
        }

        public static void releaseConnection(MySqlConnection conn)
        {
            conn.Close();
            conn.Dispose();
        }
    }
}
